// api-response.ts
export default class ApiResponse<T> {
  code: number;
  result: T | any;
  message: string;

  constructor(code: number, result: T | null, message: string) {
    this.code = code;
    this.result = result;
    this.message = message;
  }
  public isSuccess(): boolean {
    return this.code === 200 && this.result !== null;
  }

  // 静态方法，从原始响应对象创建 ApiResponse 实例
  public static fromResponse<T>(response: { code: number; result: T | null; message: string }): ApiResponse<T> {
    return new ApiResponse(response.code, response.result, response.message);
  }
}
